package ar.edu.unq.mongodbexample.tests.persitence;

import java.util.ArrayList; 
import java.util.List;

import ar.edu.unq.mongodbexample.homes.ProfessorHome;
import ar.edu.unq.mongodbexample.model.Professor;
import ar.edu.unq.mongodbexample.persistence.MongoDBManager;
import junit.framework.TestCase;

public class ProfessorHomeTestCase extends TestCase {
	ProfessorHome home;
	List<Professor> professors;
	public void setUp(){
		home=new ProfessorHome();
		professors=createProfessors();
	}
	public void tearDown(){
		MongoDBManager.getInstance().getDataStore().getCollection(Professor.class).drop();
	}
	
	public void testSaveAndGetById(){
		Professor professor=new Professor(31702882,"Cejas","Cristian","cristian.cejas@gmail.com");
		home.save(professor);
		assertEquals("Cristian", home.findById(31702882).getName());
	}
	
	public void testSaveAllAndGetAllStudents() {
    	home.saveAll(professors);
    	List<Professor> professorsList= home.getAll();
        assertEquals(professorsList.size(), 4);
    }
	
	public List<Professor> createProfessors(){
		List<Professor> professorsList=new ArrayList<Professor>();
		professorsList.add(new Professor(00000001,"UnApellido1","UnNombre1","unemailmorphia1@mail.com"));
		professorsList.add(new Professor(00000002,"UnApellido2","UnNombre2","unemailmorphia2@mail.com"));
		professorsList.add(new Professor(00000003,"UnApellido3","UnNombre3","unemailmorphia3@mail.com"));
		professorsList.add(new Professor(00000004,"UnApellido4","UnNombre4","unemailmorphia4@mail.com"));
        return professorsList;
	}
}
